package flc.ast.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.stark.more.MorePrefUtil;
import com.stark.more.about.DefAboutActivity;

import flc.ast.R;
import flc.ast.activity.SettingActivity;
import flc.ast.databinding.FragmentMyBinding;
import stark.common.basic.base.BaseNoModelFragment;
import stark.common.basic.base.BaseWebviewActivity;
import stark.common.basic.event.EventStatProxy;
import stark.common.basic.event.usersys.UserSysEventProxy;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MyFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MyFragment extends BaseNoModelFragment<FragmentMyBinding> {


    @Override
    protected int onCreate() {
        return R.layout.fragment_my;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent5(getActivity(), mDataBinding.event5Container);

        mDataBinding.llSetting.setOnClickListener(this);
        mDataBinding.llPrivacy.setOnClickListener(this);
        mDataBinding.llAgreement.setOnClickListener(this);
        mDataBinding.llFeedback.setOnClickListener(this);
        mDataBinding.llAbout.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.llSetting://设置
                startActivity(SettingActivity.class);
                click(mDataBinding.llSetting);
                break;
            case R.id.llPrivacy://隐私政策
                BaseWebviewActivity.openAssetPrivacy(getActivity());
                click(mDataBinding.llPrivacy);
                break;
            case R.id.llAgreement://用户协议
                BaseWebviewActivity.openAssetTerms(mContext);
                click(mDataBinding.llAgreement);
                break;
            case R.id.llFeedback://意见反馈
                BaseWebviewActivity.openFeedback(getActivity());
                click(mDataBinding.llFeedback);
                break;
            case R.id.llAbout://关于我们
                startActivity(new Intent(getActivity(), DefAboutActivity.class));
                click(mDataBinding.llAbout);
                break;
        }
    }

    @Override
    protected void initData() {
        boolean showPersonalRecommend = MorePrefUtil.showPersonalRecommend();
        boolean showUser = UserSysEventProxy.getInstance().supportUserSys();
        if (!showPersonalRecommend && !showUser) {
            mDataBinding.llSetting.setVisibility(View.GONE);
        } else {
            mDataBinding.llSetting.setVisibility(View.VISIBLE);
        }
    }

    private void click(View view) {
        view.setBackgroundColor(Color.parseColor("#FFFFFF"));
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                view.setBackgroundColor(Color.parseColor("#A3FFFFFF"));
            }
        }, 100);
    }

}